package cn.edu.hunau.dao.impl;

import cn.edu.hunau.dao.BannerDao;
import cn.edu.hunau.pojo.Banner;
import cn.edu.hunau.utils.DBUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 苏佳
 * @Date 2022 12 04 16 56
 **/
public class BannerDaoImpl implements BannerDao {

    @Override
    public List<Banner> queryMainBannerOnline(String online) {
        String sql="select id,pic,`order`,online,pid,bgcolor from t_mainbanner where online=? order by `order`";
        return DBUtils.query(sql, rs -> {
            List<Banner> datas = new ArrayList<>();
            while(rs.next()){
                Banner banner = new Banner();
                banner.setId(rs.getInt("id"));
                banner.setPic(rs.getString("pic"));
                banner.setOrder(rs.getInt("order"));
                banner.setOnline(rs.getString("online"));
                banner.setPid(rs.getInt("pid"));
                banner.setBackgroundColor(rs.getString("bgcolor"));
                datas.add(banner);
            }
            return datas;
        },online);
    }

    @Override
    public List<Banner> queryKillingBannerOnline(String online) {
        String sql="select id,pic,`order`,online,pid,name,price from t_killingbanner where online=? order by `order`";
        return DBUtils.query(sql, rs -> {
            List<Banner> datas = new ArrayList<>();
            while(rs.next()){
                Banner banner = new Banner();
                banner.setId(rs.getInt("id"));
                banner.setPic(rs.getString("pic"));
                banner.setOrder(rs.getInt("order"));
                banner.setOnline(rs.getString("online"));
                banner.setPid(rs.getInt("pid"));
                banner.setName(rs.getString("name"));
                banner.setPrice(rs.getDouble("price"));
                datas.add(banner);
            }
            return datas;
        },online);
    }
}
